package org.zoomdev.zoom.validator.impl;

import org.zoomdev.zoom.validator.Validator;
import org.zoomdev.zoom.validator.annotations.Range;

public class RangeValidator implements Validator {
    private final long min;
    private final long max;

    private final String message;

    public RangeValidator(Range range) {
        this.min = range.min();
        this.max = range.max();
        this.message = range.message();
    }

    @Override
    public boolean isValid(Object value) {

        if (!(value instanceof Number)) return true;
        long num = ((Number) value).longValue();
        return num >= min && num <= max;
    }

    @Override
    public String getMessage() {
        return message;
    }
}